package com.linkdood.app.web.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 系统信息
 *
 * @author YunJ
 */
@Api(value = "系统信息", tags = {"系统信息"})
@RestController
@RequestMapping("/api/system")
public class SystemResource {

    @Value("${app.version}")
    private String systemVersion;

    @Value("${vrv.web.serviceHost}")
    private String serviceHost;

    @Value("${vrv.web.serviceToken}")
    private String serviceToken;

    @Value("${server.servlet.context-path}")
    private String contextPath;


    @ApiOperation(value = "查看系统版本", notes = "查看系统版本")
    @GetMapping(value = "/version")
    public ResponseEntity<?> getSystemVersion() {
        Map<String, String> map = new HashMap<>(1);
        map.put("version", systemVersion);
        return ResponseEntity.ok(map);
    }

    @ApiOperation(value = "查看服务配置信息", notes = "查看服务配置信息")
    @GetMapping(value = "/service/config")
    public ResponseEntity<?> getWebConfig() {
        Map<String, String> map = new HashMap<>(2);
        /**
         * serviceUrl 中， serviceHost 后的 api 指向的是如下接口:
         * {@link com.linkdood.app.web.rest.SyncMessageResource#getNotice}
         */
        map.put("serviceUrl", serviceHost + contextPath + "/api/ddio/message");
        map.put("serviceToken", serviceToken);
        return ResponseEntity.ok(map);
    }

}
